<extend name="common:base" />
<block name="content">
   <div id="header">
        <div class="header">
            <h1 class="tit">商品列表</h1>
            <!--<p class="goback">-->
                <!--<a class="return" href="javascript:history.go(-1);">返回</a>-->
                <!--&lt;!&ndash;<a class="close" href="#"></a>&ndash;&gt;-->
            <!--</p>-->
            <!--<p class="more"><a class="share"></a></p>-->
        </div>
    </div>
    <div class="classify-center">
        <form action="" method="get" id="form">
            <input type="hidden" name="m" value="home"/>
            <input type="hidden" name="c" value="good"/>
            <input type="hidden" name="a" value="agentgoods"/>
            <input type="hidden" name="sale"  value="{$_GET['sale']}" id="sale"/>
            <input type="hidden" name="id"  value="{$_GET['id']}" id="iid"/>
            <input type="hidden" name="new"  value="1" id="new"/>
            <input type="hidden" name="ranking"  value="1" id="ranking"/>
            <input type="hidden" name="price"  value="{$price}" id="price"/>
            <input type="hidden" name="brand_id"  value="{$brand_id}" id="brand_id"/>
            <input type="hidden" name="model" id="model" value="0">
            <input type="hidden" name="model_id" id="model_id" value="{$model}">
            <input type="hidden" id="is_agent" value="{$is_agent}">
            <input type="hidden" class="visitor" value="{$visitor}">


            <div class="left-classify">
                <div class="classify-search">
                    <a class="go-home" href="{:U('Index/index', array('shop_id'=>session('url_shop_id')))}"><img src="{:C('__STATIC__')}{$theme}/Static/img/go-home.png"/></a>
                    <input class="phony-ipt" placeholder="搜索" type="text" value="{$_GET['mName']}"/>
                    <div class="switch-over">
                        <if condition="$model eq 2">
                            <img class="switch-img" src="{:C('__STATIC__')}{$theme}/Static/img/switchover.png"/>
                        <else />
                            <img class="switch-img" src="{:C('__STATIC__')}{$theme}/Static/img/switch.png"/>
                        </if>
                    </div>
                </div>
                <div class="classify-function">
                    <ul class="classify-tab">
                        <li class="synthesize">
                            综合
                            <span class="down-arrow"></span>
                            <div class="opt-for">
                                <if condition="$new eq 1">
                                    <i class="ranking">综合排序</i>
                                    <i class="new-priority  classify_img">新品优先</i>
                                    <else />
                                    <i class="ranking classify_img">综合排序</i>
                                    <i class="new-priority">新品优先</i>
                                </if>

                            </div>
                        </li>
                        <li class="sales-volume">
                            销量
                            <if condition="$sale eq 'plus'">
                                <span class="up-arrow"></span>
                            <else />
                                <span class="down-arrow"></span>
                            </if>
                        </li>
                        <li class="classify-price">
                            价格
                            <if condition="$price eq 'plus'">
                                <span class="up-arrow"></span>
                            <else />
                                <span class="down-arrow"></span>
                            </if>

                            <div class="opt-fora"></div>
                        </li>
                        <li class="classify-brand">
                            品牌<span class="down-arrow"></span>
                            <div class="brand-statement">
                                <volist name="brands" id="brand">
                                    <a href="javascript:;" iid="{$brand['brand_id']}" class="brand_id"><i <if condition="$brand_id eq $brand['brand_id']">class="classify_img"</if>>{$brand['b_name']}</i></a>
                                </volist>
                            </div>
                        </li>
                    </ul>
                    <div class="pattern">
                        <if condition="$model neq 2">
                            <ul class="image-text">
                                <volist name="agentgoods" id="agentgoods" key="k" >
                                    <a href="{:U('Good/goodsdetail', array('id'=>$agentgoods['id']))}">
                                        <li>
                                            <div class="image-img"><img src="{$agentgoods['thumb']}" /></div>
                                            <div class="text-text">
                                                <p class="text-tit">
                                                    {$agentgoods['g_name']|mb_substr=0,8,'utf-8'}...
                                                </p>
                                                <p class="text-price">
                                                    <span>￥</span>{$agentgoods['price']}
                                                </p>
                                                <p class="text-volume">
                                                    销量<span>{$agentgoods['sale_num']}</span>笔
                                                </p>
                                                <a class="shopping-cart cart" href="javascript:;" good_id="{$agentgoods['id']}"></a>
                                            </div>
                                        </li>
                                    </a>
                                </volist>
                            </ul>
                        <else />
                            <div class="list" >
                                <volist name="agentgoods2" id="agentgoods" key="k" >

                                        <dl>
                                            <a href="{:U('Good/goodsdetail', array('id'=>$agentgoods['id']))}">
                                                <dt><img src="{$agentgoods['thumb']}"/></dt>
                                            </a>
                                            <dd>
                                                <a href="{:U('Good/goodsdetail', array('id'=>$agentgoods['id']))}">
                                                    <p class="list-tit">
                                                        {$agentgoods['g_name']|mb_substr=0,8,'utf-8'}...
                                                    </p>
                                                </a>
                                                <p class="list-price">
                                                    <span>￥</span>{$agentgoods['price']}
                                                </p>
                                                <p class="list-volume">
                                                    销量<span>{$agentgoods['sale_num']}</span>笔
                                                </p>

                                                <span class="list-shopping-cart cart" href="javascript:;" good_id="{$agentgoods['id']}"></span>
                                            </dd>
                                        </dl>
                                </volist>
                            </div>
                        </if>
                    </div>
                </div>
            </div>
            <div class="right-classify">
                <div class="ri-search">
                    <div class="go-back"><img src="{:C('__STATIC__')}{$theme}/Static/img/gback.png"/></div>
                    <input class="ri-phony" placeholder="一叶子面膜" name="mName" type="text" value="{$_GET['mName']}" id="mName"/>
                    <input type="submit" value="搜索" class="true-search"/>
                </div>
            </div>
        </form>
    </div>
    <div class="dropload-load" id="loading" style="display: none;"><span class="loading"></span>加载中...</div>
</block>
<block name="CSS">
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/weChat_system.css"/>
</block>

<block name="JS">
    <script src="{:C('__STATIC__')}{$theme}/Static/js/classify.js"></script>
    <script type="text/javascript">
        var url = "{:C('__STATIC__')}{$theme}/Static/img/";
        var model = "{$model}";
        var m_name = "{$c_name}";
        $(function() {

            var mName = $('#mName').val();

            //点击不同的销量
            $('.sales-volume').click(function() {
                var sale = $('#sale').val();
                (sale == 'reduce') ? $('#sale').val('plus'): $('#sale').val('reduce');
                location.href = $('#form').attr("action") + "?m=&c=Good&a=agentgoods&id="+$('#iid').val()+ '&sale='+$('#form').find("input[name='sale']").val()+'&mName='+mName+'&model={$model}';
            });

            //点击不同的品牌
            $('.brand_id').click(function() {
               var iid = $(this).attr('iid');
               $('#brand_id').val(iid);
               location.href = $('#form').attr("action") + "?m=&c=Good&a=agentgoods&id="+$('#iid').val()+ '&brand_id='+$('#form').find("input[name='brand_id']").val()+'&mName='+mName+'&model={$model}';
            });

            //新品优先
            $('.new-priority').click(function() {
               location.href = $('#form').attr("action") + "?m=&c=Good&a=agentgoods&id="+$('#iid').val()+ '&new='+$('#form').find("input[name='new']").val()+'&mName='+mName+'&model={$model}';
            });

            //综合排序
            $('.ranking').click(function() {
               location.href = $('#form').attr("action") + "?m=&c=Good&a=agentgoods&id="+$('#iid').val()+ '&ranking='+$('#form').find("input[name='ranking']").val()+'&mName='+mName+'&model={$model}';
            });

            //搜索商品
            $('.true-search').click(function(event) {
                var m_name = $('#form').find("input[name='mName']").val();
                if (m_name != '') {
                    location.href = $('#form').attr("action") + "?m=&c=Good&a=agentgoods&id="+$('#iid').val()+ '&mName='+m_name+'&model={$model}';
                } else {
                    location.href = $('#form').attr("action") + "?m=&c=Good&a=agentgoods&id="+$('#iid').val()+'&model={$model}';
                }
                event.preventDefault();
            });

            //给购物车传递数据
            $(document).on('click', '.cart',function() {
                var session = $(".visitor").val();
                if(session == ''){
                    //location.href =  "?m=Home&c=Login&a=index";
                    location.href =  "{:U('Login/index', array('shop_id'=>session('url_shop_id')))}";
                }

                $.ajax({
                    url:"{:U('GoodShopcart/addcart')}",
                    data: {
                        'good_id': $(this).attr('good_id'),
                        'num':1
                    },
                    type: 'post',
                    success: function (msg) {
                        if(msg == 1) {
                            layer.msg('添加购物车成功！', {icon: 1});
                        }else if(msg == -1){
                            layer.msg("商品信息不存在",{icon:2});
                        }else if(msg == -2){
                            layer.msg("商品数量错误",{icon:2});
                        }else if(msg == -3){
                            layer.msg("商品状态错误",{icon:2});
                        }else if(msg == -4){
                            layer.msg("规格信息错误",{icon:2});
                        }
                    }
                });
            });
        });

        /**
         * 继续加载猜您喜欢
         * */
        var before_request = 1; // 上一次请求是否已经有返回来, 有才可以进行下一次请求
        var page = 1 ;
        function ajax_sourch_submit(){
            if(before_request == 0)// 上一次请求没回来 不进行下一次请求
                return false;
            before_request = 0;
            page ++;
            var model = $('#model_id').val();
            $.ajax({
                type : "post",
                url:"{:U('Good/moreagent')}",
                data: {
                    params : "{$params}",
                    page: page,
                    model: model
                },
                beforeSend:function() {
                    $('#loading').show();
                },
                success: function(data)
                {
                    var dom = (model == 2) ? '.list' : '.image-text';
                    if (data != 1) {
                        $(dom).append(data);
                        before_request = 1;
                    } else {
                        $('#loading').text('没有更多的数据！');
                    }
                }
            });
        }

        $(".switch-over").click(function () {
            var mName = $('#mName').val();
            var model_id = $('#model_id').val();
            model_id = (model_id == 2) ? 0 :2;
            location.href = $('#form').attr("action") + "?m=&c=Good&a=agentgoods&id="+$('#iid').val()+ '&mName='+mName+ '&model='+model_id;
            if( $(".image-text").css("display") == "none" ){
                $(".switch-img").attr("src",url+"switch.png");
                $('#model').attr( "value","1" );
            }else{
                $(".switch-img").attr("src",url+"switchover.png");
                $('#model').attr( "value","2" );
            }
            page = 1;
            $('#loading').show();
            $('#loading').text("加载中...");
        });
    </script>
</block>
